package br.com.lazyprogrammer.spaceshooter.manager;

import br.com.limaogames.framework.gl.Texture;
import br.com.limaogames.framework.gl.TextureRegion;
import br.com.limaogames.framework.impl.GLGame;
import br.com.limaogames.framework.util.Display;

/**
 * Created by LimaoGames on 19/8/2014.
 */
public class ImageManager implements ManagerListener {

    private final String ROOT = "images/";
    private final String BACKGROUND = ROOT + "backgrounds/";
    private final String METEORS = ROOT + "meteors/";
    private final String SHIPS = ROOT + "ships/";

    private final String NAME_SPRITESHEET = "spritesheet.png";

    public static boolean loadComplete = false;

    public static Texture backgroundBlack;
    public static Texture backgroundBlue;
    public static Texture backgroundDarkPurple;
    public static Texture backgroundPurple;

    public static Texture meteors;
    public static Texture ships;

    public static TextureRegion bgBlack;
    public static TextureRegion bgBlue;
    public static TextureRegion bgDarkPurple;
    public static TextureRegion bgPurple;

    public static TextureRegion meteorBigBrown01;
    public static TextureRegion meteorBigBrown02;
    public static TextureRegion meteorBigBrown03;
    public static TextureRegion meteorBigBrown04;
    public static TextureRegion meteorBigGray01;
    public static TextureRegion meteorBigGray02;
    public static TextureRegion meteorBigGray03;
    public static TextureRegion meteorBigGray04;
    public static TextureRegion meteorMediumBrown01;
    public static TextureRegion meteorMediumBrown02;
    public static TextureRegion meteorMediumGray01;
    public static TextureRegion meteorMediumGray02;
    public static TextureRegion meteorSmallBrown01;
    public static TextureRegion meteorSmallBrown02;
    public static TextureRegion meteorSmallGray01;
    public static TextureRegion meteorSmallGray02;
    public static TextureRegion meteorTinyBrown01;
    public static TextureRegion meteorTinyBrown02;
    public static TextureRegion meteorTinyGray01;
    public static TextureRegion meteorTinyGray02;

    public static TextureRegion shipPlayerBlue01;
    public static TextureRegion shipPlayerBlue02;
    public static TextureRegion shipPlayerBlue03;
    public static TextureRegion shipPlayerBlue04;
    public static TextureRegion shipPlayerGreen01;
    public static TextureRegion shipPlayerGreen02;
    public static TextureRegion shipPlayerGreen03;
    public static TextureRegion shipPlayerGreen04;
    public static TextureRegion shipPlayerOrange01;
    public static TextureRegion shipPlayerOrange02;
    public static TextureRegion shipPlayerOrange03;
    public static TextureRegion shipPlayerRed01;
    public static TextureRegion shipPlayerRed02;
    public static TextureRegion shipPlayerRed03;
    public static TextureRegion shipPlayerRed04;
    public static TextureRegion shipPlayerYellow01;

    public ImageManager() {

    }

    @Override
    public void load(GLGame game) {
        background(game);
        meteor(game);
        ship(game);
        loadComplete = true;
    }

    @Override
    public void reload() {
        backgroundBlack.reload();
        backgroundBlue.reload();
        backgroundDarkPurple.reload();
        backgroundPurple.reload();

        meteors.reload();
        ships.reload();
    }

    private void background(GLGame game) {
        backgroundBlack = new Texture(game, BACKGROUND + "bg_black.png");
        backgroundBlue = new Texture(game, BACKGROUND + "bg_blue.png");
        backgroundDarkPurple = new Texture(game, BACKGROUND + "bg_darkpurple.png");
        backgroundPurple = new Texture(game, BACKGROUND + "bg_purple.png");

        bgBlack = new TextureRegion(backgroundBlack, 0, 0, Display.width, Display.height);
        bgBlue = new TextureRegion(backgroundBlue, 0, 0, Display.width, Display.height);
        bgDarkPurple = new TextureRegion(backgroundDarkPurple, 0, 0, Display.width, Display.height);
        bgPurple = new TextureRegion(backgroundPurple, 0, 0, Display.width, Display.height);
    }

    private void meteor(GLGame game) {
        meteors = new Texture(game, METEORS + NAME_SPRITESHEET);

        meteorBigBrown01 = new TextureRegion(meteors, 0, 0, 96, 96);
        meteorBigBrown02 = new TextureRegion(meteors, 0, 192, 96, 96);
        meteorBigBrown03 = new TextureRegion(meteors, 96, 0, 160, 128);
        meteorBigBrown04 = new TextureRegion(meteors, 96, 256, 64, 64);
        meteorBigGray01 = new TextureRegion(meteors, 0, 96, 96, 96);
        meteorBigGray02 = new TextureRegion(meteors, 0, 288, 96, 96);
        meteorBigGray03 = new TextureRegion(meteors, 96, 128, 160, 128);
        meteorBigGray04 = new TextureRegion(meteors, 96, 320, 64, 64);
    }

    private void ship(GLGame game) {
        ships = new Texture(game, SHIPS + NAME_SPRITESHEET);

        shipPlayerBlue01 = new TextureRegion(ships, 64, 0, 64, 64);
        shipPlayerBlue02 = new TextureRegion(ships, 64, 64, 64, 32);
        shipPlayerBlue03 = new TextureRegion(ships, 64, 96, 64, 64);
        shipPlayerBlue04 = new TextureRegion(ships, 64, 160, 64, 64);

        shipPlayerGreen01 = new TextureRegion(ships, 128, 0, 64, 64);
        shipPlayerGreen02 = new TextureRegion(ships, 128, 64, 64, 32);
        shipPlayerGreen03 = new TextureRegion(ships, 128, 96, 64, 64);
        shipPlayerGreen04 = new TextureRegion(ships, 128, 160, 64, 64);

        shipPlayerOrange01 = new TextureRegion(ships, 192, 0, 64, 64);
        shipPlayerOrange02 = new TextureRegion(ships, 192, 64, 64, 32);
        shipPlayerOrange03 = new TextureRegion(ships, 192, 96, 64, 64);

        shipPlayerRed01 = new TextureRegion(ships, 0, 0, 64, 64);
        shipPlayerRed02 = new TextureRegion(ships, 0, 64, 64, 32);
        shipPlayerRed03 = new TextureRegion(ships, 0, 96, 64, 64);
        shipPlayerRed04 = new TextureRegion(ships, 0, 160, 64, 64);

        shipPlayerYellow01 = new TextureRegion(ships, 192, 160, 64, 64);
    }

}
